<?php
/**
 * HTTP异常类模块
 * 
 * @author jlpay-sdk-php
 * @version 1.0.0
 */

namespace JLPay\Core\Http;

use Exception;
use Throwable;

/**
 * HTTP执行异常类
 */
class HttpExecutionException extends Exception
{
    /**
     * 原始异常
     * @var Throwable|null
     */
    private $originalException;
    
    /**
     * 构造函数
     * 
     * @param string $message 异常消息
     * @param Throwable|null $previous 原始异常
     * @param int $code 异常代码
     */
    public function __construct($message = "", Throwable $previous = null, $code = 0)
    {
        parent::__construct($message, $code, $previous);
        $this->originalException = $previous;
    }
    
    /**
     * 获取原始异常
     * 
     * @return Throwable|null
     */
    public function getOriginalException()
    {
        return $this->originalException;
    }
}

/**
 * HTTP状态码异常类
 */
class HttpStatusCodeException extends Exception
{
    /**
     * HTTP状态码
     * @var int
     */
    private $statusCode;
    
    /**
     * 响应内容
     * @var string
     */
    private $responseBody;
    
    /**
     * 构造函数
     * 
     * @param int $statusCode HTTP状态码
     * @param string $responseBody 响应内容
     * @param string $message 异常消息
     */
    public function __construct($statusCode, $responseBody = '', $message = '')
    {
        $this->statusCode = $statusCode;
        $this->responseBody = $responseBody;
        
        if (empty($message)) {
            $message = "HTTP响应异常状态码: {$statusCode}";
        }
        
        parent::__construct($message, $statusCode);
    }
    
    /**
     * 获取HTTP状态码
     * 
     * @return int
     */
    public function getStatusCode()
    {
        return $this->statusCode;
    }
    
    /**
     * 获取响应内容
     * 
     * @return string
     */
    public function getResponseBody()
    {
        return $this->responseBody;
    }
} 